package structural.facade.custom;

import structural.facade.custom.devices.*;

/**
 * 家庭影院
 */
public class HomeTheaterFacade {
    private CdPlayer cdPlayer;
    private Curtain curtain;
    private Fan fan;
    private Light light;
    private Tv tv;
    private Thermometer thermometer;
    private Clock clock;

    public HomeTheaterFacade(CdPlayer cdPlayer, Curtain curtain, Fan fan, Light light, Tv tv, Thermometer thermometer, Clock clock) {
        this.cdPlayer = cdPlayer;
        this.curtain = curtain;
        this.fan = fan;
        this.light = light;
        this.tv = tv;
        this.thermometer = thermometer;
        this.clock = clock;
    }

    /**
     * 开始播放电影
     */
    public void watchMovie() {
        System.out.println(" == 播放影片 == ");
        this.curtain.close();
        this.tv.on();
        this.tv.play();
        this.comfortable();
        this.light.darken();
    }

    /**
     * 开始播放cd
     */
    public void listenCd() {
        System.out.println(" == 播放Cd == ");
        this.cdPlayer.on();
        this.cdPlayer.play();
        this.comfortable();
    }

    /**
     * 调整到舒适状态
     */
    public void comfortable() {
        System.out.println(" == 调整舒适度： == ");
        this.thermometer.showTemperature();
        if (this.thermometer.isHot()) {
            this.fan.on();
            this.fan.swing();
        } else if (this.thermometer.isCold()) {
            this.fan.off();
        }

        if (this.clock.isDay()) {
            this.light.off();
        } else if (this.clock.isNight()) {
            this.light.on();
        }
    }

    /**
     * 结束
     */
    public void close() {
        System.out.println(" == 关闭家庭影院 == ");
        this.curtain.open();
        this.tv.off();
        this.light.off();
        this.cdPlayer.off();
        this.fan.off();
    }

}
